﻿using System;
using BenchMark.CarGame;
using BenchMark.PlatformerGame;
using BenchMark.ShootingGame;
using FarseerPhysics.Dynamics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using BenchMark.ParticleSystems;
using Syngine;
using Syngine.Content;
using Syngine.Input;
#if !(WINDOWS_PHONE || ANDROID)
using Syngine.Input.Mouse;
#endif
using Syngine.Input.Keyboard;
using Syngine.Input.Touch;
using Syngine.Physics;

namespace BenchMark
{
	/// <summary>
	/// This is the main type for your game
	/// </summary>
	public class Game1 : PhysicsGameBase
	{
		public Game1()
		{
			Content.RootDirectory = "Content";
			IsMouseVisible = true;
		}

		/// <summary>
		/// Allows the game to perform any initialization it needs to before starting to run.
		/// This is where it can query for any required services and load any non-graphic
		/// related content.  Calling base.Initialize will enumerate through any components
		/// and initialize them as well.
		/// </summary>
		protected override void Initialize()
		{
			var input = GameContext.Input;

#if !(WINDOWS_PHONE || ANDROID)
			input.Set(new MouseHandler());
			input.Set(new MarqueeHandler());
#endif
			input.Set(new TouchHandler());
			input.Set(new KeyboardHandler());
			
			var screenController = Controller.ScreenController;
			Controller.AddScreen(new ParticleSystemScreen(screenController));
			//Controller.AddScreen(new ShootingGameScreen(screenController));
			//Controller.AddScreen(new PlatformerScreen(screenController));
			Controller.AddScreen(new CarGameScreen());
			Controller.AddScreen(new FpsScreen(screenController));
			Controller.AddScreen(new BenchMarkPauseScreen());
			GameContext.Input.If(i => i.WasReleased(Keys.Escape)).Call(ExitGameCallback);

			GameContext.Input.If(a => a.WasPressed(Keys.Space)).Call(c =>
			{
				if (GameState.IsPaused)
				{
					GameState.Resume();
				}
				else
				{
					GameState.Pause();
				}
			});

			base.Initialize();
		}

		public override World CreateWorld()
		{
			return new World(new Vector2(0, 9.8f));
			//return new World(Vector2.Zero);
		}

		protected override void Draw(GameTime gameTime)
		{
			GraphicsDevice.Clear(Color.Black);
			base.Draw(gameTime);
		}

		private void ExitGameCallback(InputCallbackContext context)
		{
			Exit();
		}
	}
}